package flc.ast.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.listener.OnPageChangeListener;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.activity.SelPicActivity;
import flc.ast.adapter.IndicatorAdapter;
import flc.ast.adapter.MyBannerAdapter;
import flc.ast.adapter.PlacardAdapter;
import flc.ast.bean.MyFrameBean;
import flc.ast.databinding.FragmentPlacardBinding;
import flc.ast.utils.Content;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link PlacardFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class PlacardFragment extends BaseNoModelFragment<FragmentPlacardBinding> {

    private IndicatorAdapter indicatorAdapter;

    @Override
    protected int onCreate() {
        return R.layout.fragment_placard;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);
        List<MyFrameBean> listFrame = new ArrayList<>();
        listFrame.add(new MyFrameBean(R.drawable.h11, R.drawable.y1, 378, 624, 63, 500, 38, 320, false));
        listFrame.add(new MyFrameBean(R.drawable.h22, R.drawable.y2, 378, 624, 0, 630, 0, 380, false));
        listFrame.add(new MyFrameBean(R.drawable.h33, R.drawable.y3, 378, 624, 0, 630, 0, 380, false));
        listFrame.add(new MyFrameBean(R.drawable.h44, R.drawable.y4, 378, 624, 145, 490, 74, 305, false));
        listFrame.add(new MyFrameBean(R.drawable.h55, R.drawable.y5, 378, 624, 0, 630, 0, 380, false));
        listFrame.add(new MyFrameBean(R.drawable.h66, R.drawable.y6, 378, 624, 80, 378, 45, 334, false));
        listFrame.add(new MyFrameBean(R.drawable.h77, R.drawable.y7, 378, 624, 160, 561, 55, 322, false));
        PlacardAdapter bannerAdapter = new PlacardAdapter(listFrame);
        mDataBinding.placardBanner.setAdapter(bannerAdapter, true);//false不无限循环
        mDataBinding.placardBanner.setCurrentItem(4);
        mDataBinding.placardBanner.setBannerGalleryEffect(30, 24);//40两边露出距离，20图片之间距离
        mDataBinding.placardBanner.isAutoLoop(true);//false不自动轮播
        //点击监听
        mDataBinding.placardBanner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(Object data, int position) {
                SelPicActivity.myFrameBean=listFrame.get(position);
                SelPicActivity.selPosition=position;
                Intent intent = new Intent(mContext, SelPicActivity.class);
                intent.putExtra(Content.Flag, Content.Placard);
                startActivity(intent);
            }
        });
        mDataBinding.placardBanner.addOnPageChangeListener(new OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                indicatorAdapter.setSelPosition(position);
                indicatorAdapter.notifyDataSetChanged();
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        mDataBinding.rvIndicatorList.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.HORIZONTAL,false));
        indicatorAdapter=new IndicatorAdapter();
        indicatorAdapter.setSelPosition(3);
        indicatorAdapter.setList(listFrame);
        mDataBinding.rvIndicatorList.setAdapter(indicatorAdapter);
    }

    @Override
    protected void initData() {

    }
}